package com.kangyi.admin.controller;

import com.kangyi.admin.mapper.AdminUserMapper;
import com.kangyi.admin.service.ToExamineService;
import com.kangyi.constant.MessageConstant;
import com.kangyi.context.BaseContext;
import com.kangyi.dto.GuestsStayingPageQueryDTO;
import com.kangyi.exception.PermissionsException;
import com.kangyi.result.PageResult;
import com.kangyi.result.Result;
import com.kangyi.result.ToExaminePageResult;
import com.kangyi.vo.AdminUserVO;
import com.kangyi.vo.ToExamineDetailVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.record.TextObjectRecord;
import org.apache.poi.util.Removal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Blank
 * @version 1.0
 */
@RestController
@RequestMapping("/admin/toExamine")
@Slf4j
@Api(tags = "养老院管理员-入住审核相关接口")
public class ToExamineController {

    @Autowired
    private ToExamineService toExamineService;


    @GetMapping("/page")
    @ApiOperation("入住审核分页查询")
    public Result<ToExaminePageResult> pageQuery(GuestsStayingPageQueryDTO guestsStayingPageQueryDTO){
        log.info("入住审核分页查询:{}",guestsStayingPageQueryDTO);
        try {
            ToExaminePageResult toExaminePageResult = toExamineService.pageQuery(guestsStayingPageQueryDTO);
            return Result.success(toExaminePageResult,"查询成功！");
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }


    @PostMapping("/agree")
    @ApiOperation("批量同意")
    @CacheEvict(cacheNames = "toExamine_", allEntries = true)
    public Result agree(@RequestParam List<Integer> ids){
        log.info("批量同意:{}",ids);
        try {
            toExamineService.agree(ids);
        } catch (Exception e) {
            return Result.error("操作失败！");
        }
        return Result.success("操作成功！");
    }

    @PostMapping("/refuse")
    @ApiOperation("批量拒绝")
    @CacheEvict(cacheNames = "toExamine_", allEntries = true)
    public Result refuse(@RequestParam List<Integer> ids){
        log.info("批量拒绝:{}",ids);
        try {
            toExamineService.refuse(ids);
        } catch (Exception e) {
            return Result.error("操作失败！");
        }
        return Result.success("操作成功！");
    }

    @GetMapping("/detail/{id}")
    @ApiOperation("查询入住人信息详情")
//    @Cacheable(cacheNames = "toExamine_", key = "'adminDetail_'+#id")
    public Result<ToExamineDetailVO> detail(@PathVariable Integer id){
        log.info("查询入住人信息详情:{}",id);
        try {
            ToExamineDetailVO toExamineDetailVO = toExamineService.detail(id);
            return Result.success(toExamineDetailVO,"查询成功！");
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }
}
